package com.lebang.controller.api.bus;

import com.lebang.common.Require;
import com.lebang.feign.bus.MemberBussRouteplanningRecordFeign;
import com.lebang.model.RequestUserInfo;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 公交用户路线规划记录
 *
 * @Author: ljx
 * @Date: 2020/12/18
 */
@Api(tags = "公交用户路线规划记录")
@RestController
@RequestMapping("/api/routeplanning")
public class MemberBussRouteplanningRecordApi {
    @Autowired
    private MemberBussRouteplanningRecordFeign feign;

    @Require
    @ApiOperation("车站站地点记录")
    @PostMapping("/get")
    public JsonData get(HttpServletRequest request, @ApiParam(name = "城市id") @RequestParam("cityId") String cityId) {
        if (cityId == null) {
            return Callback.fail("fail", "查询失败");
        }
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.get(userInfo, cityId);
    }

    @Require
    @ApiOperation("添加车站站地点记录")
    @PostMapping("/add")
    public JsonData add(HttpServletRequest request, String starRoute,String endRoute, String cityId) {
        if (cityId == null) {
            return Callback.fail("fail", "添加失败");
        }
        if (starRoute == null || endRoute == null  ){
            return Callback.fail("fail", "添加失败");
        }
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.add(userInfo, starRoute,endRoute, cityId);
    }

    @Require
    @ApiOperation("删除车站站地点记录")
    @PostMapping("/del")
    public JsonData del(HttpServletRequest request,String uuId) {
        RequestUserInfo userInfo = new RequestUserInfo(request);
        if (uuId == null) {
            return Callback.fail("fail", "删除失败");
        }
        return feign.del(userInfo, uuId);
    }

    @Require
    @ApiOperation("删除所有车站站地点记录")
    @PostMapping("/delall")
    public JsonData delall(HttpServletRequest request,
                           @ApiParam(name = "城市id") @RequestParam("cityId") String cityId) {
        if (cityId == null) {
            return Callback.fail("fail", "删除失败");
        }
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.delall(userInfo, cityId);
    }
}
